package com.jvbc.xoso;

import java.util.ArrayList;
import java.util.List;

import com.jvbc.xoso.arrayadapter.DanhMucArrayAdapter;
import com.jvbc.xoso.bean.DanhMuc;
import com.jvbc.xoso.db.DanhMucDataSource;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

public class ListCategoryActivity extends Activity{

	ArrayList<DanhMuc> danhmucArry = new ArrayList<DanhMuc>();
	DanhMucArrayAdapter adapter;
	ListView dataList;
	DanhMucDataSource db;
	public static int id;
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_rss);
		
		Intent in = getIntent();
		id = in.getIntExtra("pageID", 0);
		
		db = new DanhMucDataSource(this);
		List<DanhMuc> danhmuc = db.getAllDanhMuc(id);
		for (DanhMuc cn : danhmuc) {
			//add contacts data in arrayList
			danhmucArry.add(cn);
	
		}
		adapter = new DanhMucArrayAdapter(this, R.layout.list_row_rss,danhmucArry);
		/*dataList= (ListView) findViewById(R.id.lvRss);*/
		dataList.setAdapter(adapter); 
		
		dataList.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> listView, View view, int position,
					long id) {
				DanhMuc danhmuc = danhmucArry.get(position);
				Intent inCategory = new Intent(getApplicationContext(),ListReaderActivity.class);
				inCategory.putExtra("CategoryName", danhmuc.getLink());
				Toast.makeText(getApplicationContext(), ""+danhmuc.getLink(), Toast.LENGTH_LONG).show();
				startActivity(inCategory);
			}
		});
	}
}
